#include <reg51.h>

#define BAUD9600_11M   0xFD //11.0592MHz 0xFD BAUD=9600
#define BAUD600_12M    0xCC //12MHz 0xCC BAUD=600

#define BAUD BAUD600_12M

unsigned char rec_data = 0xFF;

void uart_isr() interrupt 4
{
	if(TI == 1) TI = 0;
	if(RI == 1) 
	{
		RI = 0;
		rec_data = SBUF;
		//SBUF = rec_data;
	}
}

void Uart_Init() 
{
	TMOD = 0x20;//timer1 mode2
	TH1=BAUD;
	TL1=BAUD;
	SCON = 0x50;//uart mode1
	PCON = 0x00; //SMOD bit = 0
	TR1 = 1;//timer1 run
	RI = 0;
	EA = 1;
	ES = 1;//enable serial interrupt
}